#include <string>

using namespace std;

class Solution {
public:
	int romanToInt(string s) {
		char prevC = '#';
		int ans = 0;
		for (int i = 0; i < s.size(); i++) {
			switch (s[i]) {
			case 'I':
				ans += 1; prevC = s[i]; break;
			case 'V':
				ans += 5;
				if (prevC == 'I') { ans -= 2; }
				prevC = s[i]; break;
			case 'X':
				ans += 10;
				if (prevC == 'I') { ans -= 2; }
				prevC = s[i]; break;
			case 'L':
				ans += 50;
				if (prevC == 'X') { ans -= 20; }
				prevC = s[i]; break;
			case 'C':
				ans += 100;
				if (prevC == 'X') { ans -= 20; }
				prevC = s[i]; break;
			case 'D':
				ans += 500;
				if (prevC == 'C') { ans -= 200; }
				prevC = s[i]; break;
			case 'M':
				ans += 1000;
				if (prevC == 'C') { ans -= 200; }
				prevC = s[i]; break;
			}
		}

		return ans;
	}
};


//int main() {
//	Solution s;
//	s.romanToInt("M");
//
//}